package GUI;


import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;

import client.ClientConsole;

import Library.LateReport;
import Library.StatisticInfo;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;


public class GUI_Report extends JPanel
{
	/**r instance of GUI_Report*/
	public static GUI_Report r;
	/**clc instance of ClientConsole*/
	private ClientConsole clc;
	/**ar instance of GUI_ActivityReport*/
	public GUI_ActivityReport ar;
	/**lo instance of GUI_Loan_Report*/
	private GUI_Loan_Report lo;
	/**lr instance of GUI_LateReport*/
	private GUI_LateReport lr;
	
	/**@param cc current ClientConsole
	 * @param gl instance of current GUI_LogIn
	 * @param mm instance of current GUI_ManagerMenu*/
	public GUI_Report(ClientConsole cc, final GUI_LogIn gl,final GUI_ManagerMenu mm)
	{
		setLayout(null);
		this.setSize(700,600);
		r=this;
		clc=cc;
		JButton btnActivityReport = new JButton("Activity Report");
		btnActivityReport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ar=new GUI_ActivityReport(clc,gl,r);
				gl.setContentPane(ar);
			}
		});
		btnActivityReport.setBounds(26, 75, 158, 23);
		add(btnActivityReport);
		
		JLabel lblChooseTypeOf = new JLabel("Choose type of report:");
		lblChooseTypeOf.setBounds(26, 29, 179, 23);
		add(lblChooseTypeOf);
		
		JButton btnLoanReport = new JButton("Loan Report");
		btnLoanReport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String s[]={"StatisticInfoReport"};
				try {			
					clc.client.sendToServer(s);
					while(clc.client.flag==0)
					    System.out.print("");
					    clc.client.flag=0;
					    StatisticInfo statisticInfo =(StatisticInfo)clc.client.message;
						lo= new GUI_Loan_Report(clc,statisticInfo,r);
			     		gl.setContentPane(lo);
						    
					  
					    	
				} catch (IOException e1) {
					e1.printStackTrace();
				}	// send message to server

				
		}});
		btnLoanReport.setBounds(26, 122, 158, 23);
		add(btnLoanReport);
		
		JButton btnLateInLoan = new JButton("Late in Loan Reoprt");
		btnLateInLoan.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String s[]={"lateReport"};
				try {			
					clc.client.sendToServer(s);
					while(clc.client.flag==0)
					    System.out.print("");
					    clc.client.flag=0;
					    LateReport lateReport =(LateReport)clc.client.message;
					    if (lateReport.getFlg()==0)
							JOptionPane.showMessageDialog(new JFrame(),"There are no data to display");
					    else
					    {
					    	lr=new GUI_LateReport(clc,gl,r,lateReport);
							gl.setContentPane(lr);
					    }
				} catch (IOException e1) {
					e1.printStackTrace();
				}	// send message to server
				

			}
		});
		btnLateInLoan.setBounds(26, 171, 158, 23);
		add(btnLateInLoan);
		
		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				gl.setContentPane(mm);
			}
		});
		btnBack.setBounds(372, 305, 89, 23);
		add(btnBack);
		
		JButton btnLogOut = new JButton("Log Out");
		btnLogOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				gl.LogOut();
			}
		});
		btnLogOut.setBounds(495, 305, 89, 23);
		add(btnLogOut);
	}

}
